package com.example.exception;

import com.example.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description: 全局异常处理
 * @Author zx
 * @Date 2024/2/28 19:59
 * @Version 1.0
 */
@ControllerAdvice
public class GlobalExceptionHandle {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(MyException.class)
    @ResponseBody
    public Result error(MyException myException){
        myException.printStackTrace();
        return Result.fail();
    }
}
